/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nxlv2.nomad.view;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author Administrateur
 */
public class Login extends JFrame {

    private JLabel ereurLabel;
    private JTextField emailTField;
    private JTextField mdpTField;
    private boolean connect = false;
    
    public Login() {
        super();
        build();
    }
    
    private void build(){
        setTitle("Authentification");
        setSize(300, 200);
        setLocationRelativeTo(null);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        setContentPane(buildContentPane());
    }
    
    private JPanel buildContentPane(){       
        
        JPanel panel = new JPanel();
	panel.setLayout(new GridBagLayout());
        
        GridBagConstraints gbc = new GridBagConstraints();
 
	ereurLabel = new JLabel("");
        ereurLabel.setForeground(Color.red);
	JLabel emailLabel = new JLabel("Email");
	JLabel mdpLabel = new JLabel("Password");
        
        emailTField = new JTextField();
        mdpTField = new JPasswordField();
        JButton validerButton = new JButton(new LoginAction(this, "Valider"));
        
        emailTField.setColumns(10);
        mdpTField.setColumns(10);
        
        //FIXME à retirer, uniquement pour simplifier le dev
        emailTField.setText("x.delarue@viacesi.fr");
        mdpTField.setText("passe");
        
        
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridheight = 1;
        gbc.gridwidth = 2;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel.add(ereurLabel,gbc);        
        
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.ipadx = 20;
        gbc.ipady = 10;
	panel.add(emailLabel, gbc); // A1
        
        gbc.gridwidth = GridBagConstraints.REMAINDER;        
        gbc.gridx = 1;
        gbc.ipady = 5;
	panel.add(emailTField, gbc); // A2
        
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.ipady = 10;
	panel.add(mdpLabel, gbc); // B1
        
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridx = 1;
        gbc.ipady = 5;
	panel.add(mdpTField, gbc); // B2
        
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridx = 1;
        gbc.gridy = 3;
        panel.add(validerButton, gbc); // C2
 
	return panel;
    }

    public JLabel getEreurLabel() {
        return ereurLabel;
    }

    public JTextField getEmailTField() {
        return emailTField;
    }

    public JTextField getMdpTField() {
        return mdpTField;
    }

    public boolean isConnect() {
        return connect;
    }

    public void setConnect(boolean connect) {
        this.connect = connect;        
    }   
}
